#!/bin/sh
echo -n 'Page Name:'
read page

author='吴建涛(fortomorrow@163.com)'
date=`date`

#通用组件的目录
mkdir -p app/com/
#js模块
mkdir -p app/$page/mods
#less模块
mkdir -p app/$page/style

echo "/**
 * Page: $page
 * Author: $author
 * Date: $date
 */
require.config({
  baseUrl: 'doctor-info',
  shim: {
    \"jquery\" : {
      \"exports\" : '$'
    },
    \"bootstrap\": {
      \"deps\": ['jquery']
    },
    \"underscore\": {
      \"deps\"    : ['jquery'],
      \"exports\" : '_'
    },
    \"jquery.form\" : {
      \"deps\" : [\"jquery\"]
    }
  },
  paths: {
    \"jquery\"      : \"//libs.baidu.com/jquery/2.0.0/jquery.min\",
    \"bootstrap\"   : \"//libs.baidu.com/bootstrap/3.0.3/js/bootstrap.min\",
    \"underscore\"  : \"//libs.baidu.com/underscore/1.3.3/underscore-min\",
    \"jquery.form\" : \"//cdnjs.cloudflare.com/ajax/libs/jquery.form/3.51/jquery.form.min\"
  }
});
require([], function(){
});
" >> app/$page/index.js
echo "app/$page/index.js 创建成功"

echo "/**
 * Page: $page
 * Author: $author
 * Date: $date
 */
" >> app/$page/index.less
echo "app/$page/index.less 创建成功"

echo "<!DOCTYPE html>
<html lang=\"zh\">
<head>
  <meta charset=\"UTF-8\">
  <title>$page</title>

  <!--仅在需要将这个网页作为一个app图标的时候
  <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">
  -->
  <meta name=\"viewport\" content=\"width=device-width,inital-scale=1.0,maximum-scale=1.0,user-scalable=no;\" />

  <!--使用一些公用的CDN，除非需要定制或者修改这些库的时候，不要自己在服务器上再放一份这些文件-->
  <link rel=\"stylesheet\" href=\"http://cdnjs.cloudflare.com/ajax/libs/normalize/3.0.1/normalize.min.css\" type=\"text/css\" charset=\"utf-8\">
  <link href=\"http://libs.baidu.com/bootstrap/3.0.3/css/bootstrap.min.css\" rel=\"stylesheet\">

  <link rel=\"stylesheet\" href=\"$page/index.css\" type=\"text/css\" charset=\"utf-8\">
</head>
<body>
  <script>
  var script = document.createElement('script');
  script.src = 'http://cdnjs.cloudflare.com/ajax/libs/require.js/2.1.15/require.min.js';
  if(window.location.search.indexOf('debug') !== -1){
    script.setAttribute('data-main','$page/index')
  }else{
    script.setAttribute('data-main','$page/index-min')
  }
  document.body.appendChild(script)
  </script>
</body>
</html>
" >> app/${page}.html
echo "app/${page}.html 创建成功"

echo "r.js -o name=index out=app/$page/index-min.js baseUrl=app/$page  " >> build.sh
